package com.flyxteam.commons.crypto;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * 使用MD5算法进行加密
 * <ul>
 * <li>2017-01-01 | ChrisX | + create</li>
 * </ul>
 * @author ChrisX
 */
public class MD5Util {

    private MD5Util() {}
    
    public static String md5Hex(String source) {
        if (source == null || source.isEmpty()) {
            return null;
        }
        return DigestUtils.md5Hex(source);
    }

    public static String md5Lower32(String source) {
        return md5Hex(source);
    }
    
    public static String md5Upper32(String source) {
        return md5Hex(source).toUpperCase();
    }
    
    public static String md5Lower16(String source) {
        return md5Hex(source).substring(8, 24);
    }
    
    public static String md5Upper16(String source) {
        return md5Hex(source).substring(8, 24).toUpperCase();
    }
}